package com.lxy.seata.service.impl;

import com.lxy.seata.dao.TAccountDao;
import com.lxy.seata.service.TAccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.concurrent.TimeUnit;

/**
 * @author lixinyang
 * @className: TAccountServiceImpl
 * @description: TODO
 * @date 2022/05/02日  22:49
 */

@Service
@Slf4j
public class TAccountServiceImpl implements TAccountService {

    @Autowired
    private TAccountDao tAccountDao;

    @Override
    public int decrease(Long userId, BigDecimal money) throws InterruptedException {
        log.info("扣减余额开始");
        try {
            TimeUnit.SECONDS.sleep(20);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        int decrease = tAccountDao.decrease(userId, money);
        log.info("扣减余额结束");
        return decrease;
    }
}
